/**
 * movieclip frame label check
 * Copyright (c) 2009 cmiscm.com
 * date of final modification : 2009. 10. 24 
*/
package com.cmiscm.utils.movieclip
{
	import flash.display.MovieClip;
	import flash.events.Event;
	
	/**
	 * when make Linkage extends <code>FrameLabel</code> then take Event first, end, frame-label in Movieclip.
	 * <p>
	 * Linkage 생성시 <code>FrameLabel</code>를 상속받으면 처음, 끝, 프레임라벨에서 이벤트를 받을 수 있음.
	 */	
	public class FrameLabel extends MovieClip
	{
		public static const FRAME_FIRST:String = 'frame_first';
		public static const FRAME_END:String = 'frame_end';
		public static const FRAME_LABEL:String = 'frame_label';
		
		public function FrameLabel()
		{
			super();
			this.stop();
			setting();
		}

		private function setting():void
		{
			var arr:Array = this.currentLabels;
			var total:int = arr.length;
			for (var i:int=0; i<total; i++) this.addFrameScript(arr[i].frame-1, addLabelEvent);
			this.addFrameScript(0, addFirstEvent);
			this.addFrameScript(this.totalFrames - 1, addEndEvent);
		}
		
		private function addFirstEvent():void
		{
			this.dispatchEvent(new Event(FrameLabel.FRAME_FIRST));
		}
		private function addEndEvent():void
		{
			this.dispatchEvent(new Event(FrameLabel.FRAME_END));
		}
		private function addLabelEvent():void
		{
			this.dispatchEvent(new Event(FrameLabel.FRAME_LABEL));
		}
		
	}
}